package model

import (
	"auth/model/entity"
)

type ResourceCreateRequest struct {
	Name string `json:"name" binding:"required"`

	Resource string `json:"resource" binding:"required"`
}

type ResourceByParameterRequest struct {
	Name string `json:"name" binding:"required"`

	Resource string `json:"resource" binding:"required"`
}

type ResourceUpdateRequest struct {
	ID int64 `json:"id"`

	Name string `json:"name" binding:"required"`

	Resource string `json:"resource" binding:"required"`
}

type ResourceListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	ID int64 `json:"id"`

	Name string `json:"name" validate:"required"`

	Resource string `json:"resource"`
}

type ResourceListResponse struct {
	Total int             `json:"total"`
	Data  []*ResourceInfo `json:"data"`
}

type ResourceInfo struct {
	ID int64 `json:"id"`

	Name string `json:"name"`

	Resource string `json:"resource"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`
}

type ResourceBaseRequest struct {
	ID int64 `json:"id" binding:"required"`
}

type ResourceDeleteRequest struct {
	ID int64 `json:"id"`
}

func ResourcesEntityToDto(resources []*entity.Resource) []*ResourceInfo {
	out := make([]*ResourceInfo, 0, len(resources))
	for _, c := range resources {
		out = append(out, ResourceEntityToDto(c))
	}
	return out
}

func ResourceEntityToDto(e *entity.Resource) *ResourceInfo {
	return &ResourceInfo{

		ID: e.ID,

		Name: e.Name,

		Resource: e.Resource,

		CreatedAt: e.CreatedAt,

		UpdatedAt: e.UpdatedAt,
	}
}
